import request from '@/config/axios'
import type { ConfigData, ConfigEmailData, ConfigOrgData, ResetpasswordData } from './types'
import { Md5 } from "ts-md5";

export const saveCongigApi = (data: Partial<ConfigData>): Promise<IResponse> => {
    const resultData = {key: 'config', val: JSON.stringify(data)};
    return request.post({url: '/config/', data: resultData})
}

export const getCongigDetailApi = (): Promise<IResponse> => {
    return request.get({url: '/config/config'})
}

export const getEmailDetailApi = (): Promise<IResponse> => {
    return request.get({url: '/config/email'})
}

export const saveEmailApi = (data: Partial<ConfigEmailData>): Promise<IResponse> => {
    const resultData = {key: 'email', val: JSON.stringify(data)};
    return request.post({url: '/config/', data: resultData})
}
export const resetPassword = (data: Partial<ResetpasswordData>): Promise<IResponse> => {
    const resultData = {id: data.id, old: Md5.hashStr(data.old || ''), password: Md5.hashStr(data.password || ''), pwd: data.password};
    return request.post({url: '/user/reset', data: resultData})
}

export const getConfigOrgApi = (): Promise<IResponse> => {
    return request.get({url: '/config/org'})
}
export const saveConfigOrgApi = (data: Partial<ConfigOrgData>): Promise<IResponse> => {
    const resultData = {key: 'org', val: JSON.stringify(data)};
    return request.post({url: '/config/', data: resultData})
}